<!DOCTYPE html>
<html>
  <head>
    <title>ITBM Web TAS</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap -->
    {{ Asset::container('bootstrapper')->styles() }}

    <style type="text/css"> 
        .loaders {
            display:    block;
            position:   fixed;
            z-index:    100;
            height:     100%;
            width:      100%;
            opacity: 0.8;
            background: #fff ;
            
        }

        .loading{
            display: block;
            background: url("{{ url('../bundles/admin/img/itbm.gif'); }}")
                        50% 50% 
                        no-repeat;
        }
    </style>

  </head>
  <body>
      
  <div class="container-fluid">
    <div class="row-fluid">
      <div class="span12">
        <div class="row-fluid">
          <div class="span12">
            @include('plugins.fixedtop')
          </div>
        </div>
        <div class="row-fluid">
              <div class="muted pull-right">
                <div id="date"></div>
              </div>
        </div>
        <div class="row-fluid">
          <div class="span2">
            <!--Sidebar content-->
            {{$sidebar}}
          </div>
          <div class="span10">
            <!--Body content-->
             {{ Navigator::breadcrumb(); }}
             @if($unauthorized)
                  {{ Response::view('home/unauthorized') }}
              @else
                @include('plugins.flasher')
                @yield('content')
              @endif
          </div>
        </div>
      </div>
    </div>
  </div>
    
    {{ Asset::container('bootstrapper')->scripts() }}
    @include('admin::plugin.loggedin')
    <script>

    startTime();

    function startTime()
    {
      var _months = [ 'Januari', 'Februari', 'Mac', 'April', 'Mei', 'Jun', 'Julai', 'Ogos', 'September', 'Oktober', 'November', 'Disember' ];
      var _weekdays = [ 'Ahad', 'Isnin', 'Selasa', 'Rabu', 'Khamis', 'Jumaat', 'Sabtu' ];

      var today=new Date();
      var h=today.getHours();
      var m=today.getMinutes();
      var s=today.getSeconds();
      var dateIs = today.getDate();
      console.log()
      var day=today.getDay();
      var month=today.getMonth();
      var year=today.getFullYear();
      // add a zero in front of numbers<10
      m=checkTime(m);
      s=checkTime(s);

      var am = (h < 12 )?'AM':'PM';

      $('#date').empty().html(_weekdays[day]+' '+h+":"+m+":"+s+' '+ am + ', ');

      $('#date').append(dateIs+' '+_months[month]+' '+year+ '');
      // $('#date').append(" {{Hijri::date("d F Y"); }}");
      t=setTimeout(function(){startTime()},500);
    }

    function checkTime(i)
    {
      if (i<10){
        i="0" + i;
      }
      return i;
    }

      function profileInfo(url){

        $('#profileModal').modal('toggle');

        $.get(url, function(data,status){

          for (x in data)
          {   
            $('#updateProfileForm input[name="'+ x +'"]' ).val(data[x]);
          }

          },"json");

      }


      $('#editProfileBtn').click(function() {
        
        $.post('{{url("console/user/profile")}}', $("#updateProfileForm").serialize(),function(data) {
                sourcedata = data;
              }).success(function() { 
              
              for (x in sourcedata)
              {   
                $('#updateProfileForm input[name="'+ x +'"]' ).val(sourcedata[x]);
              }

              var notfail = '<div class="alert alert-success" >' +
                    '<button type="button" class="close" data-dismiss="alert">&times;</button>' +
                    '<strong>Kemaskini Berjaya!!!</strong> Maklumat profil berjaya dikemaskini.</div>'


              $('.modal-body').prepend(notfail);

              }).fail(function() { 

              var notfail = '<div class="alert alert-error" >' +
                    '<button type="button" class="close" data-dismiss="alert">&times;</button>' +
                    '<strong>Kemaskini Gagal!!!</strong> Maklumat profil gagal dikemaskini.</div>'


              $('.modal-body').prepend(notfail);

              });

      });



      $('#resetBtn').click(function() {

        $('body').modalmanager('loading');
        $('#resetpasswordModal').modal('loading');

        var notfail = '<div class="alert alert-success" >' +
                    '<button type="button" class="close" data-dismiss="alert">&times;</button>' +
                    '<strong>Kemaskini Berjaya!!!</strong> Kata Laluan berjaya dikemaskini.</div>';   

        var fail = '<div class="alert alert-error" >' +
                    '<button type="button" class="close" data-dismiss="alert">&times;</button>' +
                    '<strong>Kemaskini Gagal!!!</strong> Kata Laluan gagal dikemaskini.</div>';

        $.post('{{url("administrator/user/resetpassword")}}', $("#resetForm").serialize(),function(data) {
                sourcedata = data;

              }).success(function() { 
                
                sourcedata = jQuery.parseJSON(sourcedata);

                $('#resetModalBody div.alert.alert-error').remove();
                if(sourcedata.messages){
                  $('body').modalmanager('loading');
                  $('#resetpasswordModal').modal('loading').find('.modal-body').prepend(fail); 
                  validated("resetForm",sourcedata.messages);
                }else{
                  $('body').modalmanager('loading');
                  $('#resetpasswordModal').modal('loading').find('.modal-body').prepend(notfail);
                  $('#resetForm :input').val('');
                }

              }).fail(function() { 
                $('body').modalmanager('loading');
                $('#resetModalBody').modal('loading').find('.modal-body').prepend(fail); 

              });

              // 

      });


    </script>
    <script type="text/javascript">

      $(document).ajaxStart(function() {
        $('body').modalmanager('loading');
      });
      $(document).ajaxComplete(function() {
        $('body').modalmanager('loading');
      });
      
      function validated(form,data){
        
        $(".modal-body  div.control-group div.text-error").remove();
        
        for(x in data){
          $(".modal-body #"+form+" [name='"+x+"']").focus().addClass('error').attr('placeholder',data[x][0]).val('');
          $(".modal-body #"+form+" [name='"+x+"']").parents('div.control-group').append("<div  class='controls text-error'><span>"+data[x][0]+"</span></div>");

        }

      }
    </script>
    @if(!$unauthorized)
        @yield('scripts')
    @endif
    
  </body>
</html>